package netty.embeddedChannel.encoder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

/**
 * @描述:
 * @创建人: 涂有(tuyou_cd @ keruyun.com)
 * @创建时间: 2019-08-23
 */
public class AbsIntegerEncoder extends MessageToMessageEncoder<ByteBuf> {

    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
        while(msg.readableBytes() >= 4) {
            int i = Math.abs(msg.readInt());
            out.add(i);
        }
    }
}
